	<include file='Common:header' />

		<!-- /section:basics/navbar.layout -->
		<div class="main-container" id="main-container">

			<!-- #section:basics/sidebar -->

	<include file='Common:left' />


			<!-- /section:basics/sidebar -->
			<div class="main-content">
				<div class="main-content-inner">
					<div class="page-content">

                        
                        
                        <!--主题-->
						<div class="page-header">
							<h1>
								您当前操作
								<small>
									<i class="ace-icon fa fa-angle-double-right"></i>
									配置权限
								</small>
							</h1>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<form class="form-horizontal" name="admin_group_add" id="admin_group_add" method="post" action="__URL__/admin_group_runaccess">
								<input name="id" id="id" type="hidden" value="{$admin_group.id}" />
									<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 用户组名：  </label>
										<div class="col-sm-10">
											<input type="text" name="title" id="title" value="{$admin_group.title}" class="col-xs-10 col-sm-4" />
										</div>
									</div>
                                    <div class="space-4"></div>


<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>
    <td height="30" style="border-bottom:#CCCCCC solid 1px; line-height:25px;">配置规则:<br />
1、由于页面原因，权限分配为三级，同时控制左侧导航以及用户权限<br />
  </tr>
  <tr>
    <td height="30" style="border-bottom:#CCCCCC solid 1px; line-height:25px; background-color:#F4F8FB">
<label class="pos-rel">
<input type="checkbox" class="ace ace-checkbox-2"  id='chkAll' onclick='CheckAll(this.form)' value="全选"/>
<span class="lbl"> 权限全选</span>
</label>
	</td>
  </tr>
  <foreach name="datab" item="vo">
  <tr>
  <php>
  $po_1=explode(',',$admin_group['rules']);
  </php>
    <td height="50" style="border-bottom:#CCCCCC solid 1px;">
	<label>
	<input <if condition="in_array($vo['id'],$po_1)">checked</if> name="new_rules[]" class="ace ace-checkbox-2 checkbox-parent"  type="checkbox"  value="{$vo.id}" dataid="id-{$vo['id']}"  /><span class="lbl"> <strong>{$vo.title}</strong></span>	</label></td>
  </tr>
  <foreach name="vo['sub']" item="sub">
  <tr>
  <php>
  $po_2=explode(',',$admin_group['rules']);
  </php>
	<td height="40" style="padding-left:20px;border-bottom:#E7EBF8 dashed 1px; color:#333333">
	<label>
	<input <if condition="in_array($sub['id'],$po_2)">checked</if> name="new_rules[]" id="{$sub.id}" class="ace ace-checkbox-2 checkbox-parent checkbox-child"  type="checkbox"  value="{$sub.id}"  dataid="id-{$vo['id']}-{$sub['id']}" /><span class="lbl"> {$sub.title}</span></label></td>
	
	
	
	
  </tr>
										<foreach name="sub['sub']" item="subb">										
											<tr>
												<td height="30" style="padding-left:50px;border-bottom:#E7EBF8 dashed 1px; color:#666666">
													<label class="thopen">
														<input <if condition=" strpos($admin_group['rules'],','.$subb['id'].',') GT -1 ">checked</if> name="new_rules[]" class="ace ace-checkbox-2 checkbox-parent checkbox-child"  type="checkbox"  id="{$subb.id}" value="{$subb.id}" dataid="id-{$vo['id']}-{$sub['id']}-{$subb['id']}" />
														<span class="lbl" style="margin-right:20px;"> {$subb.title}</span>	
													</label>
												</td>
											</tr>
											<if condition="!empty($subb['sub'])">
											<tr>
												<td height="30" style="padding-left:70px;border-bottom:#E7EBF8 dashed 1px; color:#666666">
													<volist name="subb['sub']" id="subbb">
														<label class="thopen">
															<input <if condition=" strpos($admin_group['rules'],','.$subbb['id'].',') GT -1 ">checked</if> name="new_rules[]" class="ace ace-checkbox-2 checkbox-child" type="checkbox"  id="{$subbb.id}" value="{$subbb.id}" dataid="id-{$vo['id']}-{$sub['id']}-{$subb['id']}-{$subbb['id']}" />
															<span class="lbl" style="margin-right:10px;"> {$subbb.title}</span>	
														</label>
													</volist>
												</td>
											</tr>
											</if>
										</foreach>
									</foreach>
								</foreach>
</table>


									
									<div class="clearfix form-actions">
										<div class="col-md-offset-3 col-md-9">
											<button class="btn btn-info" type="submit">
												<i class="ace-icon fa fa-check bigger-110"></i>
												保存
											</button>

											&nbsp; &nbsp; &nbsp;
											<button class="btn" type="reset">
												<i class="ace-icon fa fa-undo bigger-110"></i>
												重置
											</button>
										</div>
									</div>
								</form>
                        	</div>
                        </div>
									<div class="hr hr-24"></div>

<include file='Common:header_nav' />

					</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->

	<include file='Common:footer' />

		</div><!-- /.main-container -->

    		<!--下拉样式以及JS-->
<link rel="stylesheet" href="__PUBLIC__/assets/css/chosen.css" />
<script src="__PUBLIC__/assets/js/chosen.jquery.js"></script>
<script type="text/javascript">


//添加操作
$(function(){
	$('#admin_group_add').ajaxForm({
		beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
		success: complete, // 这是提交后的方法
		dataType: 'json'
	});
	
	function checkForm(){

	}
	function complete(data){
		if(data.status==1){
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}else{
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
			return false;	
		}
	}
});










jQuery(function($) {
	if(!ace.vars['touch']) {
		$('.chosen-select').chosen({allow_single_deselect:true});
		$(window)
				.off('resize.chosen')
				.on('resize.chosen', function() {
					$('.chosen-select').each(function() {
						var $this = $(this);
						$this.next().css({'width': $this.parent().width()});
					})
				}).trigger('resize.chosen');

	}
});
$(function(){
	//动态选择框，上下级选中状态变化
	$('input.checkbox-parent').on('change',function(){
		var dataid=$(this).attr("dataid");
		$('input[dataid^='+dataid+']').prop('checked',$(this).is(':checked'));
	});
	$('input.checkbox-child').on('change',function(){
		var dataid=$(this).attr("dataid");
		dataid=dataid.substring(0,dataid.lastIndexOf("-"));
		var parent=$('input[dataid='+dataid+']');
		if($(this).is(':checked')){
			parent.prop('checked',true);
			//循环到顶级
			while(dataid.lastIndexOf("-")!=2){
				dataid=dataid.substring(0,dataid.lastIndexOf("-"));
				parent=$('input[dataid='+dataid+']');
				parent.prop('checked',true);
			}
		}else{
			//父级
			if($('input[dataid^='+dataid+'-]:checked').length==0){
				parent.prop('checked',false);
				//循环到顶级
				while(dataid.lastIndexOf("-")!=2){
					dataid=dataid.substring(0,dataid.lastIndexOf("-"));
					parent=$('input[dataid='+dataid+']');
					if($('input[dataid^='+dataid+'-]:checked').length==0){
						parent.prop('checked',false);
					}
				}
			}
		}
	});
	//AJAX提交
	$('#admin_group_runaccess').ajaxForm({
	success: complete, // 这是提交后的方法
	dataType: 'json'
	});
	function complete(data){
		if(data.status==1){
			layer.alert(data.info, {icon: 6}, function(index){
				layer.close(index);
				window.location.href=data.url;
			});
		}else{
			layer.alert(data.info, {icon: 5}, function(index){
				layer.close(index);
				window.location.href="{:U('admin_group_list')}";
			});
			return false;
		}
	}
});
function unselectall(){
	if(document.myform.chkAll.checked){
		document.myform.chkAll.checked = document.myform.chkAll.checked&0;
	}
}
function CheckAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.Name != 'chkAll'&&e.disabled==false)
			e.checked = form.chkAll.checked;
	}
}

</script>
		</body>
</html>
